package com.leetcode;

/**
 * 806. 写字符串需要的行数
 * 直接遍历
 *
 * @author fy
 * @date 2022/4/12 16:27
 */
public class Solution806_1 {

    private final static int MAX_WIDTH = 100;

    public int[] numberOfLines(int[] widths, String s) {
        if (s == null || s.length() == 0) {
            return new int[]{0, 0};
        }
        int lines = 1;
        int width = 0;
        for (int i = 0; i < s.length(); i++) {
            int needWidth = widths[s.charAt(i) - 'a'];
            width += needWidth;
            if (width > MAX_WIDTH) {
                lines++;
                width = needWidth;
            }
        }
        return new int[]{lines, width};
    }

}
